import { verifyAccessToken } from '~/utils/jwt-utils';
import { MOCK_ADMINS } from '~/utils/mock-data';
import { unAuthorizedResponse } from '~/utils/response';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return unAuthorizedResponse(event);
  }

  await sleep(600);

  const { page, pageSize, username, realName, roles } = getQuery(event);
  const filterList = MOCK_ADMINS.filter((item) => {
    return (
      (!username || item.username.includes(username as string)) &&
      (!realName || item.realName.includes(realName as string)) &&
      (!roles || item.roles.includes(roles as string))
    );
  });
  return usePageResponseSuccess(page as string, pageSize as string, filterList);
});
